#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    while(n--){
        unordered_set<string> team_names;
        unordered_map<string, pair<int, int>> team;
        for(int i = 0; i < 12; ++i){
            int goal1, goal2;
            string name1, name2, vsdot;
            cin >> name1 >> goal1 >> vsdot >> goal2 >> name2;
            team_names.insert(name1);
            team_names.insert(name2);
            if(goal1 > goal2){
                team[name1].first += 3;
                team[name1].second += (goal1 - goal2);
                team[name2].second -= (goal1 - goal2);
            }else if(goal1 < goal2){
                team[name2].first += 3;
                team[name1].second += (goal1 - goal2);
                team[name2].second -= (goal1 - goal2);
            }else{
                team[name1].first += 1;
                team[name2].first += 1;
            }
        }
        vector<string> sorted_team;
        for(auto s : team_names){
            sorted_team.push_back(s);
        }
        sort(sorted_team.begin(), sorted_team.end(), 
             [&](const string &s, const string &t){
                pair<int, int> a = team[s];
                pair<int, int> b = team[t];
                return (a.first == b.first ? a.second > b.second : a.first > b.first);
            });

        cout << sorted_team[0] << " " << sorted_team[1] << endl;
    }
}